execute at @s anchored eyes positioned ^ ^ ^ run summon marker ~ ~ ~ {Tags:["rmr.throw_axe_eye"]}
execute at @s anchored eyes positioned ^ ^ ^1 run summon marker ~ ~ ~ {Tags:["rmr.throw_axe_target"]}
scoreboard objectives add rmr.local.x_speed dummy
scoreboard objectives add rmr.local.y_speed dummy
scoreboard objectives add rmr.local.z_speed dummy
scoreboard objectives add rmr.local.my_x dummy
scoreboard objectives add rmr.local.my_y dummy
scoreboard objectives add rmr.local.my_z dummy

execute store result score @s rmr.local.x_speed run data get entity @n[tag=rmr.throw_axe_target] Pos[0] 100
execute store result score @s rmr.local.y_speed run data get entity @n[tag=rmr.throw_axe_target] Pos[1] 100
execute store result score @s rmr.local.z_speed run data get entity @n[tag=rmr.throw_axe_target] Pos[2] 100
execute store result score @s rmr.local.my_x run data get entity @n[tag=rmr.throw_axe_eye] Pos[0] 100
execute store result score @s rmr.local.my_y run data get entity @n[tag=rmr.throw_axe_eye] Pos[1] 100
execute store result score @s rmr.local.my_z run data get entity @n[tag=rmr.throw_axe_eye] Pos[2] 100

scoreboard players operation @s rmr.local.x_speed -= @s rmr.local.my_x
scoreboard players operation @s rmr.local.y_speed -= @s rmr.local.my_y
scoreboard players operation @s rmr.local.z_speed -= @s rmr.local.my_z

execute store result storage minecraft:rmr arguments.x_speed double 0.02 run scoreboard players get @s rmr.local.x_speed
execute store result storage minecraft:rmr arguments.y_speed double 0.02 run scoreboard players get @s rmr.local.y_speed
execute store result storage minecraft:rmr arguments.z_speed double 0.02 run scoreboard players get @s rmr.local.z_speed
execute store result storage minecraft:rmr arguments.damage double 1 run attribute @s generic.attack_damage get

tag @s add rmr.connect.owner
execute at @s anchored eyes positioned ^ ^ ^ run function rmr:entity/flying_axe/spawn with storage minecraft:rmr arguments
tag @s remove rmr.connect.owner

scoreboard objectives remove rmr.local.x_speed
scoreboard objectives remove rmr.local.y_speed
scoreboard objectives remove rmr.local.z_speed
scoreboard objectives remove rmr.local.my_x
scoreboard objectives remove rmr.local.my_y
scoreboard objectives remove rmr.local.my_z

kill @n[tag=rmr.throw_axe_eye]
kill @n[tag=rmr.throw_axe_target]

execute store result score @s rmr.item.hatchet.cd run function rmr:player/get_cooldown_by_attack_speed